# Contributor: rubicon <rubicon@mailo.com>
# Maintainer: Celeste <cielesti@protonmail.com>
pkgname=ocaml-happy-eyeballs-lwt
_pkgname=happy-eyeballs
pkgver=0.3.0
pkgrel=3
pkgdesc="Connecting to a remote host via IP version 4 or 6 using Lwt_unix"
url="https://github.com/roburio/happy-eyeballs"
arch="all !riscv64 !loongarch64" # ocaml
license="ISC"
depends_dev="
	$pkgname=$pkgver-r$pkgrel
	ocaml-domain-name-dev
	ocaml-duration-dev
	ocaml-fmt-dev
	ocaml-ipaddr-dev
	ocaml-logs-dev
	ocaml-lwt-dev
	ocaml-happy-eyeballs-dev
	ocaml-cmdliner-dev
	ocaml-dns-dev
	ocaml-mtime-dev
	"
makedepends="$depends_dev dune ocaml libev-dev gmp-dev"
subpackages="$pkgname-dev $pkgname-tools"
source="$pkgname-$pkgver.tar.bz2::https://github.com/roburio/happy-eyeballs/releases/download/v$pkgver/happy-eyeballs-$pkgver.tbz"
builddir="$srcdir/$_pkgname-$pkgver"
_ocamldir=usr/lib/ocaml

# 32-bit archs
case "$CARCH" in
	arm*|x86) options="$options textrels" ;;
esac

build() {
	dune build \
		-p happy-eyeballs-lwt \
		--verbose
}

check() {
	dune runtest --verbose
}

package() {
	dune install \
		--destdir="$pkgdir" \
		--docdir=/.omit \
		happy-eyeballs-lwt
	rm -Rf "$pkgdir"/.omit
}

dev() {
	default_dev

	cd "$pkgdir"

	local path; find $_ocamldir \( \
			-name '*.cmt' -o \
			-name '*.cmti' -o \
			-name '*.ml' -o \
			-name '*.mli' \
		\) | while read -r path
	do
		amove "$path"
	done
}

tools() {
	pkgdesc="$pkgdesc (command line utilities)"
	depends=""

	amove usr/bin
}

prepare_py_provides() {
	local datadir="${subpkgdir:-$pkgdir}"
	local pkgbasedir=${pkgbasedir:-"$startdir/pkg"}
	local controldir="$pkgbasedir"/.control.${subpkgname:-$pkgname}

	options_has "!tracedeps" && return 0

	ocaml4-abuild-find provides \
		"$datadir"/usr/lib/ocaml \
		"$controldir" \
		"$pkgver-r$pkgrel"
}

scan_python3_dependency() {
	local controldir="$2" datadir="$3"

	ocaml4-abuild-find requires \
		"$datadir"/usr/lib/ocaml \
		"$controldir"
}

sha512sums="
0c43180c635c1ac807bd6a2abbb0403afca646870936baa451f6eadcd37d1b32ceea916d7b441b190392c4b32d32292bf6196de00faa198e2e8e59c3b4fdef56  ocaml-happy-eyeballs-lwt-0.3.0.tar.bz2
"
